package com.rj.framework.component.tech.mybatis;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.Data;

/**
 * 数据操作请求参数
 *
 * @param <T>
 */
@Data
public class DataBaseRequest<T> {
    private Class<? extends BaseMapper<T>> mapperClass;
    private T reqEntity;
    private Wrapper<T> wrapper;
    private OperationType operationType;
    private IPage<T> page;

    public Wrapper<T> getWrapper() {
        if (wrapper == null) {
            return switch (operationType) {
                case FIND_ONE, DELETE -> Wrappers.lambdaQuery(reqEntity);
                case UPDATE -> Wrappers.lambdaUpdate(reqEntity);
                default -> null;
            };
        }
        return wrapper;
    }

}
